home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / ServiceMail / src / services / latex2ps.tcl < prev    next >
Encoding:
Text File  |  1993-05-07  |  1.8 KB  |  50 lines

  1. # latex2ps
  2. #
  3. # 29-May-92 weber@eitech.com
  4. #
  5. # This service will run latex, then dvi2ps on a collection of source files.
  6. # That is, the input message may contain one or more levels of multipart/mixed
  7. # bodies; the source files are retrieved from the leaves.  The sources are
  8. # named by their Content-id's.  The service result is normally a multipart
  9. # of the latex log file and the dvi2ps postscript output.
  10.  
  11. proc dolatex { switches envelope inputs } {
  12.  
  13.     # default to latexing source in the first input, use the name in the
  14.     # first switch if it exists; remove .tex extension in either case
  15.     if {[llength $switches] == 0} {
  16.     if {[getfield $inputs TYPE] == "multipart"} {
  17.         set src [getfield [lindex [getfield $inputs PARTS] 0] FILE]
  18.     } {set src [getfield $inputs FILE]}
  19.     } {set src [lindex $switches 0]}
  20.     regsub "\.tex" $src "" src
  21.     
  22.     # run latex on the main source, and if the output says that labels may have
  23.     # changed, run latex again. Then run dvi2ps
  24.     if {[catch "exec latex $src < /dev/null" lout]} {
  25.     setfield output FILE $src.log
  26.     setfield output DESCRIPTION "log file showing error"
  27.         return [mailout [turnaround $envelope] $output]
  28.     }
  29.     if {[regexp -nocase "may have changed" $lout]} {
  30.         exec latex $src < /dev/null > /dev/null
  31.     }
  32.     exec dvips -o $src.ps $src.dvi
  33.     
  34.     # now build description of outgoing two-part message containing both the latex
  35.     # log file and the postscript result
  36.     setfield part1 FILE $src.log
  37.     setfield part1 DESCRIPTION "log file"
  38.  
  39.     setfield part2 TYPE application
  40.     setfield part2 SUBTYPE postscript
  41.     setfield part2 FILE $src.ps
  42.     setfield part2 DESCRIPTION "postscript result"
  43.  
  44.     setfield output TYPE multipart
  45.     setfield output SUBTYPE mixed
  46.     setfield output PARTS [list $part1 $part2]
  47.     
  48.     return [mailout [turnaround $envelope] $output]
  49. }
  50.